package net.realsee.gcl.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.realsee.common.utils.JsonUtils;
import net.realsee.gcl.domain.bo.mes.GclMesOperateResult;
import net.realsee.gcl.domain.bo.mes.GclMesTaskCancelReq;
import net.realsee.gcl.domain.bo.mes.GclMesTaskCreateReq;
import net.realsee.gcl.domain.bo.mes.GclMesTaskUpdateReq;
import net.realsee.gcl.service.IGclMesService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 协鑫MES服务交互类
 *
 * @author
 * @since 2023/8/22 13:27
 */
@SaIgnore
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/mes")
public class GclMesController {

    private final IGclMesService gclMesService;

    /**
     * 创建任务
     */
    @PostMapping("/taskCreate")
    public GclMesOperateResult taskCreate(@RequestBody GclMesTaskCreateReq taskCreateReq) {
        log.info("[协鑫MES][任务创建][开始]，参数={}", JsonUtils.toJsonString(taskCreateReq));
        GclMesOperateResult result = gclMesService.taskCreate(taskCreateReq);
        log.info("[协鑫MES][任务创建][完成]，结果={}", JsonUtils.toJsonString(result));
        return result;
    }

    /**
     * 任务取消
     */
    @PostMapping("/taskCancel")
    public GclMesOperateResult taskCancel(@RequestBody GclMesTaskCancelReq taskCancelReq) {
        log.info("[协鑫MES][任务取消][开始]，参数={}", JsonUtils.toJsonString(taskCancelReq));
        GclMesOperateResult result = gclMesService.taskCancel(taskCancelReq);
        log.info("[协鑫MES][任务取消][完成]，结果={}", JsonUtils.toJsonString(result));
        return result;
    }

    /**
     * 修改优先级
     */
    @PostMapping("/taskUpdate")
    public GclMesOperateResult taskUpdate(@RequestBody GclMesTaskUpdateReq taskUpdateReq) {
        log.info("[协鑫MES][调整优先级][开始]，参数={}", JsonUtils.toJsonString(taskUpdateReq));
        GclMesOperateResult result = gclMesService.taskUpdate(taskUpdateReq);
        log.info("[协鑫MES][调整优先级][完成]，结果={}", JsonUtils.toJsonString(result));
        return result;
    }

}
